package lambda;

import compiler.*;

public class Main {

	/**
	 * @param args
	 */
	
	Function fix = new Function() {
		public Object apply(Object a) {
			Function f = (Function)a;
			return f.apply(f);
		}
	};
	public static void main(String[] args) throws Exception {
		CompilerGenerator gen = new CompilerGenerator();
		gen.whitespace(" |\n|\t");
		gen.scan("lambda");
		Expression exp = (Expression)gen.compile("Expression", "(\\x,(sum x 5)) 2");
		Function succ = new Function() {
			public Object apply(Object a) {
				return ((Integer)a)+1;
			}
		};
		Function sum = Util.curry(new Function2() {
			public Object apply(Object a,Object b) {
				return ((Integer)a)+((Integer)b);
			}
		});
		
		
		Binds initial =  new Binds("sum",sum,null);
		initial = new Binds("succ", succ,initial);
		System.out.println(exp.eval(initial));

		
	}

}
